'use strict';
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { BIGINT, TINYINT } = app.Sequelize;
    const PostLike = app.model.define(
        'PostLike',
        {
            id: {type: BIGINT, primaryKey: true, autoIncrement: true},
            user_id: BIGINT,
            post_id: BIGINT,
            status: {type: TINYINT, defaultValue: 1},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'post_like',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    PostLike.associate = function () {
        app.model.Business.PostLike.belongsTo(app.model.Business.User, {
            foreignKey: 'user_id',
            targetKey: 'id',
            as: 'user'
        });
        app.model.Business.PostLike.belongsTo(app.model.Business.Post, {
            foreignKey: 'post_id',
            targetKey: 'id',
            as: 'post'
        });
    };
    return PostLike
};
